import 'dart:convert';

import 'package:shared_preferences/shared_preferences.dart';

class CacheService {
  static late SharedPreferences _prefs;
  static Future setup() async {
    _prefs = await SharedPreferences.getInstance();
  }

  static Future<bool>? putList(String key, List value) {
    return _prefs.setString(key, jsonEncode(value));
  }

  static Future<List?> getList(String key) async {
    var value = _prefs.getString(key);
    if (value == null) return null;
    return jsonDecode(value);
  }

  static Future<bool>? remove(String key) {
    return _prefs.remove(key);
  }

  static Future<bool?> getBool(String key) async {
    return _prefs.getBool(key);
  }

  static Future<String?> getString(String key) async {
    return _prefs.getString(key);
  }

  static Future<bool>? putBool(String key, bool value) {
    return _prefs.setBool(key, value);
  }

  static Future<bool>? putString(String key, String value) {
    return _prefs.setString(key, value);
  }
}
